package com.frejoys.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.frejoys.common.aop.Authority;
import com.frejoys.common.aop.Authorization;
import com.frejoys.common.constant.CommonConstant;
import com.frejoys.common.dto.agent.AgentRoleGroupPageDto;
import com.frejoys.common.dto.agent.AgentRoleGroupSaveDto;
import com.frejoys.common.dto.agent.AgentRoleGroupUpdateDto;
import com.frejoys.common.dto.common.IdDto;
import com.frejoys.common.response.Result;
import com.frejoys.common.util.RequestUtil;
import com.frejoys.common.vo.agent.AgentRoleGroupVo;
import com.frejoys.service.AgentRoleGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "代理角色组", description = "代理角色组")
@RestController
@RequiredArgsConstructor
@RequestMapping(CommonConstant.routePrefixAdmin)
@Authorization(Authority.Private)
public class AdminAgentRoleGroupController {

    private final AgentRoleGroupService agentRoleGroupService;


    /**
     * 新增代理角色组
     */
    @Operation(summary = "新增代理角色组")
    @PostMapping("/agent/roleGroup/save")
    public Result saveAgentRoleGroup(@RequestBody @Validated AgentRoleGroupSaveDto dto) {
        agentRoleGroupService.saveAgentRoleGroup(dto);
        return Result.success();
    }

    /**
     * 修改代理角色组
     */
    @Operation(summary = "修改代理角色组")
    @PostMapping("/agent/roleGroup/update")
    public Result updateAgentRole(@RequestBody @Validated AgentRoleGroupUpdateDto dto) {
        agentRoleGroupService.updateAgentGroup(dto);
        return Result.success();
    }

    /**
     * 后台查询代理角色组
     */
    @Operation(summary = "分页查询代理角色组")
    @PostMapping("/agent/roleGroup/list")
    public Result<IPage<AgentRoleGroupVo>> searchAgentRoleList(@RequestBody @Validated AgentRoleGroupPageDto dto) {
        return Result.success(agentRoleGroupService.searchAgentRoleGroupList(dto));
    }

    /**
     * 用户查询自己管理的角色组信息
     */
    //查询自己管理的代理角色组
//    @Operation(summary = "查询自己管理的代理角色组")
//    @PostMapping("/agent/roleGroup/listSelf")
//    public Result<List<AgentRoleGroupVo>> listAgentRoleGroupByUserId(){
//        return Result.success(agentRoleGroupService.listAgentRoleGroupByUserId(RequestUtil.userId()));
//    }

    @Operation(summary = "删除代理角色组")
    @PostMapping("/agent/roleGroup/delete")
    public Result deleteAgentRoleGroup(@RequestBody @Validated IdDto dto){
        agentRoleGroupService.deleteAgentRoleGroup(dto);
        return Result.success();
    }
}
